1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
// reverse_iterator::operator-> example
#include <iostream> // std::cout
#include <iterator> // std::reverse_iterator
#include <utility> // std::make_pair
#include <map> // std::map
#include <string> // std::string
int main () {
std::map<int,std::string> numbers;
numbers.insert (std::make_pair(1,"one"));
numbers.insert (std::make_pair(2,"two"));
numbers.insert (std::make_pair(3,"three"));
typedef std::map<int,std::string>::iterator map_iter;
std::reverse_iterator<map_iter> rev_end (numbers.begin());
std::reverse_iterator<map_iter> rev_iterator (numbers.end());
for ( ; rev_iterator != rev_end ; ++rev_iterator )
std::cout << rev_iterator->first << ' ' << rev_iterator->second << '\n';
return 0;
}
| |